Repository navigation
Manchester | 26-ITP-Sep | Salah Alsabhi | Sprint 2 | practice tdd - #1680
salahalsabhi wants to merge 4 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Completed practice-tdd exercises with Jest tests:
All 12 tests pass. |
| // When the function is called with these inputs, | ||
| // Then it should return 0, indicating that no occurrences of `char` were found. | ||
|
|
||
| test("should count multiple occurrences of a character including upper cases", () => { |
There was a problem hiding this comment.
There are more precise terms for describing a match that treats lowercase and uppercase letters as equivalent. Could you use AI to explore how to phrase the test description more accurately?
There was a problem hiding this comment.
Note: For functions that deal with strings, an empty string "" is usually a good edge case to test.
| return num % 100 === 11 || num % 100 === 12 || num % 100 === 13 | ||
| ? `${num}th` | ||
| : num % 10 === 1 | ||
| ? `${num}st` | ||
| : num % 10 === 2 | ||
| ? `${num}nd` | ||
| : num % 10 === 3 | ||
| ? `${num}rd` | ||
| : `${num}th`; |
There was a problem hiding this comment.
-
Storing
num % 100andnum % 10inconstvariables with meaningful names before the conditional logic could improve readability and avoid redundant calculations. -
Note:
if-elseis probably more readable than nested? :.
| expect(getOrdinalNumber(13)).toEqual("13th"); | ||
| }); | ||
|
|
||
| test("should append 'th' for numbers ending with 0, 4, or big numbers.", () => { |
There was a problem hiding this comment.
What numbers are considered big numbers?
Is 10000001 a big number?
|
Thank you for your review, I addressed those things: (clearer count tests, empty string case, simplify ordinal logic) |
Learners, PR Template
Self checklist
Task code
CYF-1060
Changelist
Practice TDD: countChar, repeatStr, getOrdinalNumber
Questions
No questions